
public class CircularArrayQueue<T> {
    private final int DEFAULT_CAPACITY=10;
    private int front,rear,count;
    private T[] queue;

    public CircularArrayQueue(int num ){
        front = 0;
        rear=0;
        count=0;
        queue = (T[])(new Object[num]);
    }
    public boolean enqueue(T element){
        if (count==queue.length)
            expandCapacity();
        queue[rear] = element;
        rear = (rear+1)%queue.length;
        count++;
        return true;
    }
    public void expandCapacity(){
        T[] larger = (T[])(new Object[queue.length*2]);
        for (int index=0;index<count;index++)
            larger[index] = queue[(front+index)%queue.length];
        front=0;
        rear=count;
        queue=larger;
    }
    public T dequeue() {
        T element;
        element = queue[front];
        queue[front] = null;
        front=(front+1)%queue.length;
        count--;
        return element;
    }
    public T first(){
        T element;
        element=queue[front];
        return element;
    }
    public boolean isEmpty(){
        if (count==queue.length)
            expandCapacity();
        if (front==rear)
            return true;
        else return false;
    }
    public int size(){
        return count;
    }
}
